package com.ilovepostcard.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ilovepostcard.R;
import com.ilovepostcard.model.Order;
import com.ilovepostcard.model.OrderItem;

public class OrderDetailView extends LinearLayout {
    
    private ImageView order_status;
    
    private TextView order_number;
    
    private TextView order_time;
    
    private PostcardGridView postcard_gridview;
    
    private TextView order_receiver;

    public OrderDetailView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        inflate();
    }

    public OrderDetailView(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate();
    }

    public OrderDetailView(Context context) {
        super(context);
        inflate();
    }
    
    public void setOrder(Order order) {
        order_number.setText("订单号：" + order.OrderID);
        order_time.setText("预计印刷时间：" + order.OrderTime);
        if (Order.STATUS_FINISHED == order.OrderStatus) {
            order_status.setVisibility(VISIBLE);
        } else {
            order_status.setVisibility(GONE);
        }
        postcard_gridview.setOrder(order);
        postcard_gridview.loadNextPage();
        StringBuilder sb = new StringBuilder();
//        OrderItem[] items = order.Items;
//        if (items != null && items.length > 0) {
//            for (int i = 0; i < items.length; i++) {
//                sb.append(items[i].AddressName).append(" ");
//            }
//        }
        order_receiver.setText(sb);
    }

    private void inflate() {
        View view = View.inflate(getContext(), R.layout.order_detail, this);
        order_status = (ImageView) view.findViewById(R.id.order_status);
        order_number = (TextView) view.findViewById(R.id.order_number);
        order_time = (TextView) view.findViewById(R.id.order_time);
        postcard_gridview = (PostcardGridView) view.findViewById(R.id.postcard_gridview_order);
        order_receiver = (TextView) view.findViewById(R.id.order_receiver);
        
    }
    
}
